class DBQueue {
    #items = {};
    #lowCount = 0;
    #count = 0;

    addFront(data) {
        if (this.#lowCount > 0) {
            this.#lowCount--;
            this.#items[this.#lowCount] = data;
        }
        else{
            for(let i = this.#count;i>0;i--){
                this.#items[i] = this.#items[i-1];
            }
            this.#items[this.#lowCount] = data;
            this.#count++;
        }
    }

    addBack(data){
        this.#items[this.#count]=data;
        this.#count++;
    }

    peekFront(){
        if(this.isEmpty()){
            return ;
        }

        return this.#items[this.#lowCount];
    }

    peekBack(){
        if(this.isEmpty()){
            return ;
        }

        return this.#items[this.#count];
    }

    delFront(){
        if (this.isEmpty()) {
            return;
        }
        let i = this.#items[this.#lowCount];
        delete this.#items[this.#lowCount];
        this.#lowCount++;
        return i;
    }

    delBack(){
        if (this.isEmpty()) {
            return;
        }
        this.#count--;
        let i = this.#items[this.#count];
        delete this.#items[this.#count];
        return i;
    }


    isEmpty() {
        return this.size() == 0;
    }

    size() {
        return this.#count - this.#lowCount;
    }

    toString(){
        let str = '';
        for(let item in this.#items){
            str+=`${this.#items[item]} `;
        }
        return str;
    }
}